<?php
    $arr = API::templateSearch(array());
    
    # Poimi templatet
    $templates = array("" => "- Not selected -");
    if (!empty($arr["list"])) {
        foreach ($arr["list"] as $template) {
            $templates[$template["hashid"]] = $template["extratext"];
        }
    }
    
    $now = time();
?>

<div class="row">
    <div class="col-sm-2">
        <label for="tplist-input-startdate">
            Valid between
        </label>
    </div>
    <div class="col-sm-10">
        <div class="input-group date form_date" data-date-format="yyyy-mm-dd">
            <?php
                FT::input("startdate",date("Y-m-d",$now),array(
                    "class"     => "form-control",
                    "id"        => "tplist-input-startdate",
                    "maxlength" => 10,
                    "readonly"  => "readonly"
                ));
            ?>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
            </span>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="tplist-input-enddate">
            &nbsp;
        </label>
    </div>
    <div class="col-sm-10">
        <div class="input-group date form_date" data-date-format="yyyy-mm-dd">
            <?php
                FT::input("enddate",date("Y-m-d",$now),array(
                    "class"     => "form-control",
                    "id"        => "tplist-input-enddate",
                    "maxlength" => 10,
                    "readonly"  => "readonly"
                ));
            ?>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
            </span>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="tplist-select-templatehashid">
            Template
        </label>
    </div>
    <div class="col-sm-10">
        <?php
            FT::select("templatehashid",$templates,array(
                "class" => "form-control",
                "id"    => "tplist-select-templatehashid"
            ));
        ?>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        &nbsp;
    </div>
    <div class="col-sm-10">
        <?php
            FT::button("Search",array(
                "class"     => "btn tplist-button btn-default",
                "id"        => "tplist-button-search",
                "disabled"  => "disabled"
            ));
        ?>
    </div>
</div>

<div class="container" id="tplist-div-search"></div>

<?php
    FT::hidden("pos",0,array(
        "id" => "tplist-input-pos"
    ));
    FT::hidden("count",20,array(
        "id" => "tplist-input-count"
    ));
?>

<script type="text/javascript">
    $(".form_date").datetimepicker({
        autoclose:      1,
        minView:        2,
        todayBtn:       1,		
        todayHighlight: 1,
        weekStart:      1
    });
    
    getViewScript("tplist",function(){
        viewTplist.initializePage();
        viewTplist.search();
    });
</script>